package com.laxcen.controller2;

import com.github.pagehelper.PageInfo;
import com.laxcen.smoke.config.MyLog;
import com.laxcen.smoke.dto.req.AbnormalGetOneReq;
import com.laxcen.smoke.dto.req.AbnormalSelectReq;
import com.laxcen.smoke.dto.req.AbnormalUpdateReq;
import com.laxcen.smoke.dto.req.RoleFlagPageReq;
import com.laxcen.smoke.entity.AbNormalRecord;
import com.laxcen.smoke.service.AbNormalService;
import com.laxcen.smoke.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

@Api(tags = "运维管理")
@RestController
@RequestMapping("/maintain")
public class AbNormalController {

    @Autowired
    private AbNormalService abNormalService;

    @ApiOperation(value = "处理告警异常",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; username &nbsp; : &nbsp; username \n" +
                    "&emsp; status &nbsp; : &nbsp; 状态(0正常 1异常) \n" +
                    "&emsp; content &nbsp; : &nbsp; 维修备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @RequiresPermissions("maintain:update")
    @PostMapping(value = "/update")
    @MyLog(operation = "处理告警异常")
    public Response update(@RequestBody AbnormalUpdateReq abnormalUpdateReq){
        return abNormalService.update(abnormalUpdateReq.getId(),abnormalUpdateReq.getUsername(),abnormalUpdateReq.getStatus(),abnormalUpdateReq.getContent());
    }

    @ApiOperation(value = "告警导航栏搜索",notes =
            "请求信息： \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 实体柜编号 \n" +
                    "&emsp; starttime &nbsp; : &nbsp; 时间左区间 \n" +
                    "&emsp; endtime &nbsp; : &nbsp; 时间右区间 \n" +
                    "&emsp; roleflag &nbsp; : &nbsp; 用户权限 (0超级管理员 1普通管理员) \n" +
                    "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
                    "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
                    "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
                    "&emsp; state &nbsp; : &nbsp; 状态(0已处理 1未处理) \n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 柜子编号 \n" +
                    "&emsp; smartboxno &nbsp; : &nbsp; 格子编号  \n" +
                    "&emsp; abnormaltype &nbsp; : &nbsp; 告警类型  1开门异常  2关门异常  3UPS异常 4存货订单异常 5取货订单异常 6设备离线\n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp; content &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; state &nbsp; : &nbsp; 状态 0已处理 1未处理 \n" +
                    "&emsp; updatetime &nbsp; : &nbsp; 维修时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
//    @RequiresPermissions("maintain:get")
    @PostMapping(value = "/get")
    public Response<PageInfo<AbNormalRecord>> get(@RequestBody AbnormalSelectReq abnormalSelectReq) throws ParseException {
        if (abnormalSelectReq.getState()==null){
            abnormalSelectReq.setState(0);
        }
        if (abnormalSelectReq.getPageNo()==null){
            abnormalSelectReq.setPageNo(1);
        }
        if (abnormalSelectReq.getPageSize()==null){
            abnormalSelectReq.setPageSize(10);
        }
        if (abnormalSelectReq.getPageNo()==null&&abnormalSelectReq.getPageSize()==null){
            abnormalSelectReq.setPageNo(1);
            abnormalSelectReq.setPageSize(10);
        }
        return abNormalService.getList(abnormalSelectReq.getSmartno(),abnormalSelectReq.getStarttime(),abnormalSelectReq.getEndtime(),abnormalSelectReq.getRoleflag(),abnormalSelectReq.getProvince(),abnormalSelectReq.getCity(),abnormalSelectReq.getArea(),abnormalSelectReq.getPageNo(),abnormalSelectReq.getPageSize(),abnormalSelectReq.getState());
    }

    @ApiOperation(value = "获取告警信息列表",notes =
            "请求信息： \n" +
            "&emsp; roleflag &nbsp; : &nbsp; 用户权限 (0超级管理员 1普通管理员) \n" +
            "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
            "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
            "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
            "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
            "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 柜子编号 \n" +
                    "&emsp; smartboxno &nbsp; : &nbsp; 格子编号  \n" +
                    "&emsp; abnormaltype &nbsp; : &nbsp; 告警类型  1开门异常  2关门异常  3UPS异常 4存货订单异常 5取货订单异常 6设备离线\n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp; content &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; state &nbsp; : &nbsp; 状态 0已处理 1未处理 \n" +
                    "&emsp; updatetime &nbsp; : &nbsp; 维修时间 \n" +
                    "&emsp; total &nbsp; : &nbsp; 总数据条数 \n" +
                    "&emsp; number &nbsp; : &nbsp; 未处理数 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @RequiresPermissions("maintain:getalllist")
    @PostMapping(value = "/getalllist")
    public Response<PageInfo<AbNormalRecord>> getAllList(@RequestBody RoleFlagPageReq roleFlagPageReq)  {
        if (roleFlagPageReq.getPageNo()==null){
            roleFlagPageReq.setPageNo(1);
        }
        if (roleFlagPageReq.getPageSize()==null){
            roleFlagPageReq.setPageSize(10);
        }
        if (roleFlagPageReq.getPageNo()==null&&roleFlagPageReq.getPageSize()==null){
            roleFlagPageReq.setPageNo(1);
            roleFlagPageReq.setPageSize(10);
        }
        return abNormalService.getAllList(roleFlagPageReq.getPageNo(),roleFlagPageReq.getPageSize(),roleFlagPageReq.getRoleflag(),roleFlagPageReq.getProvince(),roleFlagPageReq.getCity(),roleFlagPageReq.getArea());
    }


    @ApiOperation(value = "获取某一个智能柜的告警信息",notes =
            "请求信息： \n" +
            "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 柜子编号 \n" +
                    "&emsp; smartboxno &nbsp; : &nbsp; 格子编号  \n" +
                    "&emsp; abnormaltype &nbsp; : &nbsp; 告警类型  1开门异常  2关门异常  3UPS异常 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp; content &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; state &nbsp; : &nbsp; 状态 0已处理 1未处理 \n" +
                    "&emsp; updatetime &nbsp; : &nbsp; 维修时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getone")
    @RequiresPermissions("maintain:getone")
    public Response<List<AbNormalRecord>> getOne(@RequestBody AbnormalGetOneReq abnormalGetOneReq)  {
        return abNormalService.getOne(abnormalGetOneReq.getSmartno());
    }


}
